package com.two.screen.water.balance.ui.fragment.base


abstract class BaseRefreshLoadMoreFragment : BaseFragment() {

    //@BindView(R.id.mSmartRefreshLayout) lateinit var mSmartRefreshLayout: SmartRefreshLayout
    //@BindView(R.id.mRecyclerView) lateinit var mRecyclerView: RecyclerView

//    protected var mBaseRefreshLoadMoreAdapter: BaseRefreshLoadMoreAdapter? = null
//    protected var mPage = 1 // 第几页
//    protected var mPageSize = 30 // 一页有几条
//    protected var mMarketId = SPUtils.getString(Params.mar_id)
//
//    override fun initView() {
//        (mRecyclerView.itemAnimator as SimpleItemAnimator).supportsChangeAnimations = false //去闪烁
//        mBaseRefreshLoadMoreAdapter = BaseRefreshLoadMoreAdapter()
//        val spanCount = setSpanCount()
//        if (spanCount > 0) {
//            mRecyclerView.layoutManager = GridLayoutManager(context, spanCount)
//        } else {
//            mRecyclerView.addItemDecoration(
//                DividerItemDecoration(context, DividerItemDecoration.HORIZONTAL_LIST, 1, ContextCompat.getColor(App.context!!, R.color.CECECE))
//            )
//            mRecyclerView.layoutManager = LinearLayoutManager(context)
//        }
//        mRecyclerView.adapter = mBaseRefreshLoadMoreAdapter
//        mBaseRefreshLoadMoreAdapter?.bindToRecyclerView(mRecyclerView)
//        mBaseRefreshLoadMoreAdapter?.setEmptyView(R.layout.layout_status_layout_manager_empty1)
//
//        mBaseRefreshLoadMoreAdapter?.setOnLoadMoreListener({ loadMore() }, mRecyclerView)
//        /*下拉刷新 监听*/
//        mSmartRefreshLayout?.setOnRefreshListener { refresh() }
//    }
//
//    inner class BaseRefreshLoadMoreAdapter : BaseQuickAdapter<BaseData, BaseViewHolder>(getItemLayout(), null) {
//        @SuppressLint("CheckResult")
//        override fun convert(helper: BaseViewHolder, item: BaseData) {
//            this@BaseRefreshLoadMoreFragment.convert(helper, item)
//        }
//    }
//
//    override fun getRootLayout(): View = mSmartRefreshLayout
//    override fun onErrorChildClick() = getListData()
//    override fun onEmptyChildClick() = getListData()
//    override fun setOnLazyLoad(): Boolean = true
//
//    override fun onLazyLoad() = getListData()
//    override fun onLazyLoadByHiddenChanged() = getListData()
//
//    protected fun getListData() {
//        mPage = 1
//        NormalApi.getData(getParams(), getListUrl())
//            .compose(RxUtils.aLifecycle(this))
//            .subscribe(object : StatusLayoutObserver<BaseData>(activity!!, mStatusLayoutManager) {
//                override fun onSuccessNext(t: BaseBean<out BaseData>) {
//                    setData(true, listData(t))
//                }
//            })
//    }
//
//    /*加载更多*/
//    private fun loadMore() {
//        NormalApi.getData(getParams(), getListUrl())
//            .compose(RxUtils.aLifecycle(this))
//            .subscribe(object : NormalObserver<BaseData>(activity!!) {
//                override fun onSuccessNext(t: BaseBean<out BaseData>) {
//                    setData(false, listData(t))
//                    mBaseRefreshLoadMoreAdapter?.setEnableLoadMore(true)
//                }
//
//                override fun dataIsNull(t: BaseBean<out BaseData>) {
//                    super.dataIsNull(t)
//                    mBaseRefreshLoadMoreAdapter?.loadMoreEnd(false)
//                }
//
//                override fun onError(e: Throwable) {
//                    super.onError(e)
//                    mBaseRefreshLoadMoreAdapter?.loadMoreFail()
//                }
//
//            })
//    }
//
//    /*下拉刷新*/
//    protected fun refresh() {
//        mPage = 1
//        mBaseRefreshLoadMoreAdapter?.setEnableLoadMore(false) //这里的作用是防止下拉刷新的时候还可以上拉加载
//        NormalApi.getData(getParams(), getListUrl())
//            .compose(RxUtils.aLifecycle(this))
//            .subscribe(object : NormalObserver<BaseData>(activity!!) {
//                override fun onSuccessNext(t: BaseBean<out BaseData>) {
//                    setData(true, listData(t))
//                    mBaseRefreshLoadMoreAdapter?.setEnableLoadMore(true) //结束刷新
//                    mSmartRefreshLayout.finishRefresh()
//                }
//
//                override fun dataIsNull(t: BaseBean<out BaseData>) {
//                    super.dataIsNull(t)
//                    mBaseRefreshLoadMoreAdapter?.setEnableLoadMore(true)
//                    mSmartRefreshLayout.finishRefresh()
//                }
//
//                override fun onError(e: Throwable) {
//                    super.onError(e)
//                    mBaseRefreshLoadMoreAdapter?.setEnableLoadMore(true)
//                    mSmartRefreshLayout.finishRefresh(false) //结束刷新（刷新失败）
//                }
//            })
//    }
//
//    protected open fun listData(t: BaseBean<out BaseData>) = t.data?.list?.toMutableList()
//
//    protected open fun setData(isRefresh: Boolean, data: MutableList<BaseData>?) {
//        mPage++
//        val size = data?.size
//            ?: 0
//        if (isRefresh) {
//            mBaseRefreshLoadMoreAdapter?.setNewData(data)
//        } else {
//            if (size > 0) {
//                mBaseRefreshLoadMoreAdapter?.addData(data!!)
//            }
//        }
//        if (size < mPageSize) {
//            //第一页如果不够一页就不显示没有更多数据布局
//            mBaseRefreshLoadMoreAdapter?.loadMoreEnd(isRefresh)
//        } else {
//            mBaseRefreshLoadMoreAdapter?.loadMoreComplete()
//        }
//    }
//
//    abstract fun getParams(): SortedMap<String, Any?>
//    abstract fun getListUrl(): String?
//    abstract fun convert(helper: BaseViewHolder, item: BaseData)
//    abstract fun getItemLayout(): Int
//    protected open fun setSpanCount(): Int = 0
}